<!--
 * @Author: your name
 * @Date: 2021-11-02 10:20:30
 * @LastEditTime: 2022-01-18 18:40:08
 * @LastEditors: Please set LastEditors
 * @Description: 艺人列表
 * @FilePath: \star-cat-h5\src\views\artist\list.vue
-->
<template>
  <div>
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <div class="artist_list">
        <Empty v-if="emptyShow" />

        <van-list v-else v-model="loading" :finished="finished" @load="getList">
          <div class="list_item">
            <div
              v-for="item in list"
              :key="item.id"
              class="item_box"
              @click="
                () =>
                  $router.push({
                    path: '/artist_details',
                    query: { id: item.id },
                  })
              "
            >
              <div class="artist_info">
                <van-image
                  width="44"
                  height="44"
                  radius="4"
                  class="img"
                  :src="item.avatar"
                />
                <div class="artist_msg">
                  <p class="name">{{ item.name }}</p>
                  <p class="nick_name">
                    {{ item.nick_name }} / {{ item.anchor_num }}
                  </p>
                </div>
              </div>

              <div class="right_icon_box">
                <img
                  v-if="item.grade"
                  :src="require(`@/assets/artist_grade/${item.grade}.png`)"
                  class="grade_img"
                />
              </div>
            </div>
          </div>
        </van-list>
      </div>
    </van-pull-refresh>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { Toast } from "vant";
import Empty from "@/components/Empty";
import { reqList } from "@/axios/artist";
export default {
  name: "artistList",
  props: {
    searchValue: {
      default: "",
    },
  },
  components: {
    Empty,
  },
  watch: {
    searchValue() {
      this.refreshing = true;
      this.onRefresh();
    },
  },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      emptyShow: false,
      refreshing: false,
      form: {
        page: 1,
      },
    };
  },
  computed: {
    ...mapGetters(["getUrlParam", "getIsLogin", "getReview_id"]),
  },
  methods: {
    getList() {
      this.emptyShow = false;
      if (this.refreshing) {
        this.list = [];
        this.refreshing = false;
      }
      this.loading = true;
      reqList({
        ...this.form,
        create_id: this.getReview_id,
        nicknameAndIdAndname: this.searchValue,
      })
        .then((res) => {
          console.log(res);
          let { list, count } = res;
          this.loading = false;
          this.list = [...this.list, ...list];
          this.finished = count <= this.list.length;
          this.form.page += 1;
          this.emptyShow = this.list.length == 0;
        })
        .catch((err) => {
          this.loading = false;
          this.finished = true;
          Toast.fail(err);
        });
    },
    onRefresh() {
      // 清空列表数据
      this.finished = true;
      this.form.page = 1;
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.getList();
    },
  },
};
</script>

<style scoped>
@import "./css/index.css";
@import "./css/listItem.css";
.artist_list {
  min-height: 80vh;
}

.right_icon_box {
  display: flex;
  align-items: center;
  justify-content: center;
}
.grade_img{
  width: 26px;
}
</style>


